package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.mapper.OrderDetailMapper;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderStatisticsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags = "订单管理")
@RestController
@RequestMapping("/admin/order")
public class OrderController {
    @Autowired
    private OrdersService ordersService;
    /**
     * 订单搜索
     * */
    @ApiOperation("订单套件搜索")
    @GetMapping("/conditionSearch")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO dto) {
        log.info("订单搜索{}",dto);
        PageResult page = ordersService.getHistoryOrders(dto);
        return Result.success(page);
    }
    /**
     * 查询订单详细
     * */
    @GetMapping("/details/{id}")
    @ApiOperation("查询订单详细")
    public Result getDetail(OrdersPageQueryDTO dto) {
        log.info("查询订单详细{}",dto);
        PageResult page = ordersService.getHistoryOrders(dto);
        return Result.success(page.getRecords().get(0));
    }
    /**
     * 各个状态的订单数量统计
     * */
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statistics() {
        log.info("统计各状态订单数量");
        OrderStatisticsVO vo = ordersService.statistics();
        return Result.success(vo);
    }
    /**
     * 接单操作
     * */
    @PutMapping("/confirm")
    @ApiOperation("接单操作")
    public Result confirm(@RequestBody OrdersConfirmDTO dto) {
        log.info("接单{}",dto);
        ordersService.confirm(dto);
        return Result.success();
    }
    /**
     * 拒单
     * */
    @PutMapping("/rejection")
    @ApiOperation("拒单")
    public Result rejection(@RequestBody OrdersRejectionDTO dto) {
        log.info("拒单{}",dto);
        ordersService.rejection(dto);
        return Result.success();
    }
    /**
     * 取消订单
     * */
    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result cancel(@RequestBody OrdersCancelDTO dto) {
        log.info("取消订单{}",dto);
        ordersService.adminCancel(dto);
        return Result.success();
    }
    /**
     * 派送订单
     * */
    @PutMapping("/delivery/{id}")
    @ApiOperation("派送订单")
    public Result delivery(@PathVariable Long id) {
        log.info("派送订单");
        ordersService.delivery(id);
        return Result.success();
    }
    /**
     * 完成订单
     * */
    @PutMapping("complete/{id}")
    @ApiOperation("完成订单")
    public Result complete(@PathVariable Long id) {
        log.info("完成订单");
        ordersService.complete(id);
        return Result.success();
    }
}
